// pages/webview/webview.js
Page({

  /**
   * Page initial data
   */
  data: {

  },
  bindmessage(e) {
    console.log('eee', e)
  },

  /**
   * Lifecycle function--Called when page load
   */
  onLoad: function(options) {
    console.log('op', options)
    this.setData({
      url: options.url,
      desc: options.desc,
      title: options.title
    })

  },

  /**
   * Lifecycle function--Called when page is initially rendered
   */
  onReady: function() {

  },

  /**
   * Lifecycle function--Called when page show
   */
  onShow: function() {

  },

  /**
   * Lifecycle function--Called when page hide
   */
  onHide: function() {

  },

  /**
   * Lifecycle function--Called when page unload
   */
  onUnload: function() {

  },

  /**
   * Page event handler function--Called when user drop down
   */
  onPullDownRefresh: function() {

  },

  /**
   * Called when page reach bottom
   */
  onReachBottom: function() {

  },
  getMessage(e) {
    console.log(e)
    let that = this;
    let shareUrl = e.detail.data[e.detail.data.length - 1];
    that.shareUrl = JSON.parse(shareUrl);
  },
  /**
   * Called when user click on the top right corner to share
   */
  onShareAppMessage(options) {

    let entity = decodeURIComponent(options.webViewUrl)
    console.log('share', entity)
    console.log('origin', encodeURIComponent(options.webViewUrl))
    let _this = this
    let title = entity.split('title=')[1]
    let page = options.webViewUrl.split('demo.html?')[1]
    let _page = encodeURIComponent(page)
    console.log('ttt', options.webViewUrl.split('demo.html?')[1])
    return {
      title: `【德语助理】我分享了：${title}，快来看看吧!`,
      path: `/pages/index/index?page=/pages/webview/webview@${_page}`,
    }
  }

})